/**
 * 
 */
package neptune.manager.validator.rules.link;

import neptune.manager.model.topology.Link;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.ValidatorRule;
import neptune.manager.validator.Validator.Status;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class EndPointNamesDefinitionRule extends ValidatorRule<Link> {

	@Override
	public String getName() {
		return "EndPointDefinitionRule";
	}

	@Override
	protected ValidatorResult validationAlgorithm(Link toValidate,
			ValidatorResult result) {

		if (toValidate.getSource() != null) {
			if (toValidate.getSource().getNodeId() == null
					|| toValidate.getSource().getNodeId().equals("")) {
				result.setStatus(Status.ERROR);
				result.getLog().addMessage("End-point node name missing",
						MessageType.ERROR);
			}
			if (toValidate.getSource().getInterfaceId() == null
					|| toValidate.getSource().getInterfaceId().equals("")) {
				result.setStatus(Status.ERROR);
				result.getLog().addMessage("End-point interface name missing",
						MessageType.ERROR);
			}
		} else {
			result.setStatus(Status.ERROR);
			result.getLog().addMessage("Source end-point undefined",
					MessageType.ERROR);
		}
		
		
		if (toValidate.getDestination() != null) {
			if (toValidate.getDestination().getNodeId() == null
					|| toValidate.getDestination().getNodeId().equals("")) {
				result.setStatus(Status.ERROR);
				result.getLog().addMessage("End-point node name missing",
						MessageType.ERROR);
			}
			if (toValidate.getDestination().getInterfaceId() == null
					|| toValidate.getDestination().getInterfaceId().equals("")) {
				result.setStatus(Status.ERROR);
				result.getLog().addMessage("End-point interface name missing",
						MessageType.ERROR);
			}
		} else {
			result.setStatus(Status.ERROR);
			result.getLog().addMessage("Source end-point undefined",
					MessageType.ERROR);
		}

		return result;
	}

}
